<template>
    <div class="header">
        <a href="/" class="logo" style="margin-left: 15px;color: #FFF;">
            <i class="el-icon-lx-home"></i>
            经销商管理平台
        </a>
        <div class="header-right">
            <div class="header-user-con">
                <!-- 用户名下拉菜单 -->
                <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                    <span class="el-dropdown-link">
                        <i class="el-icon-lx-people"></i>
                        {{username}}
                        <i class="el-icon-caret-bottom"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item divided  command="loginout">
                            <i class="el-icon-lx-exit"></i>
                            退出登录
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                collapse: false,
                fullscreen: false,
                name: 'linxin',
                message: 2
            }
        },
        computed:{
            username(){
                let username = localStorage.getItem('ms_username');
                return username ? username : this.name;
            }
        },
        methods:{
            // 用户名下拉菜单选择事件
            handleCommand(command) {
                let _token = sessionStorage.getItem("tokenId");
                if(command === 'loginout'){
                    this.$http({
                        url: '/api/adscm/logout?tokenId='+ _token,
                        method: 'get',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                    }).then((res)=> {
                        sessionStorage.removeItem('username');
                        localStorage.removeItem('ms_username');
                        this.$router.push('/login');
                    }).catch(function (catchres) {
                        sessionStorage.removeItem('username');
                        localStorage.removeItem('ms_username');
                        this.$router.push('/login');
                    })
                }
            },
        }
    }
</script>
<style scoped>
    .header {
        position: relative;
        box-sizing: border-box;
        width: 100%;
        height: 70px;
        font-size: 22px;
        color: #fff;
    }
    .header .logo{
        float: left;
        width:250px;
        line-height: 70px;
    }
    .header-right{
        float: right;
        padding-right: 50px;
    }
    .header-user-con{
        display: flex;
        height: 70px;
        align-items: center;
    }
    .btn-bell .el-icon-bell{
        color: #fff;
    }
    .user-name{
        margin-left: 10px;
    }
    .user-avator{
        margin-left: 20px;
    }
    .user-avator img{
        display: block;
        width:40px;
        height:40px;
        border-radius: 50%;
    }
    .el-dropdown-link{
        color: #fff;
        cursor: pointer;
    }
    .el-dropdown-menu__item{
        text-align: center;
    }
</style>
